"""
__author__ = 'berlinyoung'
@File   :app.py
@Date   :2022/6/12 22:02
-*- coding: utf-8 -*-
"""
from appium import webdriver

from anxinstock_mobile.page.base import Base
from anxinstock_mobile.page.main_page import MainPage
from anxinstock_mobile.page.market_page import MarketPage


class App(Base):
    # 方法：启动app
    def start_app(self):

        if self.driver is None:
            # 创建json串
            caps = {}
            caps["platformName"] = "android"
            caps["deviceName"] = "HONORV20"
            caps["appPackage"] = "cn.com.essence.stock"
            caps["appActivity"] = "com.zztzt.android.simple.PhoneVGModule.activitys.MainActivity"
            caps["noReset"] = True
            caps["noSign"] = True
            caps["ensureWebviewsHavePages"] = True
            caps["newCommandTimeout"] = 600
            self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub",caps)
            # 隐式等待，每次在调用find_element / find_elements时激活。在5秒内动态执行下一步
            self.driver.implicitly_wait(5)
        else:
            self.driver.launch_app()
        return self

    # 方法：重启
    def restart(self):
        pass

    # 方法：销毁对象driver
    def stop(self):
        pass

    def back(self,num=3):

        for i in range(0,num):
            self.driver.back()

    def goto_main(self):
        return MainPage(self.driver)

    def goto_market(self):
        return MarketPage(self.driver)